package com.i2bt.app.set.model;

import com.i2bt.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;
import java.util.List;

public class FileChooseAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private Bitmap mIcon;
	private List<String> items;
	private List<String> paths;

	public FileChooseAdapter(Context context, List<String> it, List<String> pa) {
		mInflater = LayoutInflater.from(context);
		items = it;
		paths = pa;
		mIcon = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.files_icon_folder);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;

		if (convertView == null) {
			convertView = mInflater
					.inflate(R.layout.set_choose_path_item, null);
			holder = new ViewHolder();
			holder.text = (TextView) convertView
					.findViewById(R.id.set_choosePath_Item_path);
			holder.icon = (ImageView) convertView
					.findViewById(R.id.set_choosePath_Item_icon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		File f = new File(paths.get(position).toString());
		if (f.isDirectory()) {
			holder.text.setText(f.getName());
			holder.icon.setImageBitmap(mIcon);
		}
		return convertView;
	}

	private class ViewHolder {
		TextView text;
		ImageView icon;
	}
}
